package communication;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class ParameterizedMessageImpl implements ParameterizedMessage {
	
	private String subject = null;
	
	private Map<String, String> parameters;
	
	private Object attachment  = null;

	/**
	 * 
	 */
	private static final long serialVersionUID = 3256412216183265320L;
	
	public ParameterizedMessageImpl() {
		this.parameters = new HashMap<String, String>();
	}
	
	public ParameterizedMessageImpl(String subject) {
		this();
		
		this.subject = subject;
	}
	
	public ParameterizedMessageImpl(String subject, Object attachment) {
		this(subject);
		
		this.attachment = attachment;
	}

	@Override
	public String getParameter(String name) {
		if (parameters.containsKey(name)) {
			return parameters.get(name);
		}
		
		return null;
	}

	@Override
	public void setParameter(String name, String value) {
		parameters.put(name, value);
	}

	@Override
	public void setAttachment(Serializable attachment) {
		this.attachment = attachment;
	}

	@Override
	public Object getAttachment() {
		return attachment;
	}

	@Override
	public Map<String, String> getParameters() {
		return parameters;
	}

	@Override
	public String getSubject() {
		return subject;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(this.subject);
		sb.append("; ");
		sb.append(this.parameters.toString());
		
		return sb.toString();
	}

}
